package com.mx.kn.cstf2.dao.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import javax.sql.DataSource;

import kn.cstf2.implementation.Sql.ImplementationSql;
import kn.cstf2.transition.Bean.TransitionBean;
import kn.mx.cstf2.sql.TransitionSql;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.mx.kn.cstf2.dao.ImplementationDao;
import com.mx.kn.cstf2.dto.LinksDto;

@Repository
@Component("implementationDao")
public class ImplementationDaoImpl implements ImplementationDao {

	private JdbcTemplate jdbcStksf2;
	private JdbcTemplate jdbcCustomerSalesToolKit;

	@Autowired
	public void setDataSourceStkfsf2(@Qualifier("dataSourceStkfsf2") DataSource DataSourceStkfsf2) {
		this.jdbcStksf2 = new JdbcTemplate(DataSourceStkfsf2);
	}
	
	@Autowired
	public void setDataSourceCustomerSalesToolKit(@Qualifier("dataSourceCustomerSalesToolKit")
			DataSource dataSourceCustomerSalesToolKit) {
		this.jdbcCustomerSalesToolKit = new JdbcTemplate(dataSourceCustomerSalesToolKit);
		
	}
	
	@Override
	public List<LinksDto> getLinksTransition(TransitionBean transition) throws SQLException{
		String sql = "SELECT * FROM links WHERE \"idTransition\" = ? order by id DESC";
		List<LinksDto> links = jdbcStksf2.query(
				sql, new Object[] {transition.getId()},new BeanPropertyRowMapper(LinksDto.class));
	 
		return links;
	}
	
	@Override
	public List<LinksDto> insertLink(TransitionBean transition,
			String link, String description, String displayName)
			throws SQLException {
	  String sql ="INSERT INTO links (\"idTransition\",link,descripcion,\"nombreMostrar\") VALUES (?,?,?,?)";
				
	  int rows = jdbcStksf2
				.update(sql, new Object[] {
						transition.getId(), link, description, displayName });
		
		return getLinksTransition(transition);
	}
	
	@Override
	public void updateStatusDocumentsCop(boolean status,String date,String fechas, TransitionBean transition) throws SQLException{
		
		String sql = ImplementationSql.UPDATE_STATUS_DOCUMENT_COP;
		 int rows = jdbcStksf2
					.update(sql, new Object[] {status, date, fechas, transition.getId()});
		
	}
	
	@Override
	public void updateStatusDocumentsContacts(boolean status, String date,String fecha, TransitionBean transition) throws SQLException{
		String sql = ImplementationSql.UPDATE_STATUS_DOCUMENT_CONTACTS;
		  
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsReporting(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql= ImplementationSql.UPDATE_STATUS_DOCUMENT_REPORTING;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsSos(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql= ImplementationSql.UPDATE_STATUS_DOCUMENT_SOS;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsConditions(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql = ImplementationSql.UPDATE_STATUS_DOCUMENT_CONDITIONS;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsCielID(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql = ImplementationSql.UPDATE_STATUSDOCUMENT_CIELID;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsCielQ(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql =  ImplementationSql.UPDATE_STATUS_DOCUMEWNT_CIELQ;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsCarrier(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql =  ImplementationSql.UPDATE_STATUS_DOCUMENT_CARRIER;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsWorking(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql =  ImplementationSql.UPDATE_STATUS_DOCUMENT_WORKING;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsSop(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql =  ImplementationSql.UPDATE_STATUS_DOCUMENT_SOP;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}

	@Override
	public void updateStatusDocumentsKpi(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql =  ImplementationSql.UPDATE_STATUS_DOCUMENT_KPI;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
	
	@Override
	public void updateStatusDocumentsBilling(boolean status, String date, String fecha, TransitionBean transition) throws SQLException{
		String sql =  ImplementationSql.UPDATE_STATUS_DOCUMENT_BILLING;
		int rows = jdbcStksf2
				.update(sql, new Object[] {status, date, fecha, transition.getId()});
	}
}
